package org.jz.gae.redbook.spb.server.controller;

import org.jz.gae.redbook.spb.server.helper.FamilyHelper;
import org.jz.gae.redbook.spb.shared.FamilyEntityView;

import com.google.appengine.api.datastore.Entity;
import com.google.appengine.api.datastore.KeyFactory;

public class FamilyUtils
{
	public static void reflectEntityToView(
			Entity family,
			FamilyEntityView newFamily)
	{
		newFamily.setFamilyKey(KeyFactory.keyToString(family.getKey()));
		newFamily.setFamilyAlias((String)family.getProperty(FamilyHelper.FAMILY_ALIAS));
		newFamily.setFamilyEnglerCode(((Long)family.getProperty(FamilyHelper.FAMILY_ENGLER_CODE)).intValue());
		newFamily.setFamilyLatName((String)family.getProperty(FamilyHelper.FAMILY_LAT_NAME));
		newFamily.setFamilyLatNameAuthor((String)family.getProperty(FamilyHelper.FAMILY_LAT_AUTHOR));
		newFamily.setFamilySynName((String)family.getProperty(FamilyHelper.FAMILY_SYN_NAME));
		newFamily.setFamilySynNameAuthor((String)family.getProperty(FamilyHelper.FAMILY_SYN_AUTHOR));
		newFamily.setFamilyRusName((String)family.getProperty(FamilyHelper.FAMILY_RUS_NAME));
		newFamily.setFamilyNote((String)family.getProperty(FamilyHelper.FAMILY_NOTE));
	}
	
    public static void reflectViewToEntity(
    		FamilyEntityView _FamilyToEdit,
			Entity family)
	{
		family.setProperty(FamilyHelper.FAMILY_ALIAS, _FamilyToEdit.getFamilyAlias());
		family.setProperty(FamilyHelper.FAMILY_ENGLER_CODE, _FamilyToEdit.getFamilyEnglerCode());
		family.setProperty(FamilyHelper.FAMILY_LAT_NAME, _FamilyToEdit.getFamilyLatName());
		family.setProperty(FamilyHelper.FAMILY_LAT_AUTHOR, _FamilyToEdit.getFamilyLatNameAuthor());
		family.setProperty(FamilyHelper.FAMILY_SYN_NAME, _FamilyToEdit.getFamilySynName());
		family.setProperty(FamilyHelper.FAMILY_SYN_AUTHOR, _FamilyToEdit.getFamilySynNameAuthor());
		family.setProperty(FamilyHelper.FAMILY_RUS_NAME, _FamilyToEdit.getFamilyRusName());
		family.setProperty(FamilyHelper.FAMILY_NOTE, _FamilyToEdit.getFamilyNote());
	}

}
